<?php
/**
 * @filename Flock.php
 * @author LD King
 * @encoding UTF-8
 * @date 2008-9-19 | 下午05:03:06
 * @package 12-MVC
 * @subpackage 
 * @usage 复合模式
 * @note 
 * @copyright Copyright (c) 2007 - 2008 LD (http://mifunny.info)
 * @version $Id: $
 */

include_once 'Quackable.php';

class Flock implements Quackable {
	
	/**
	 * 叫嚣者
	 *
	 * @var array
	 */
	public $quackers;
	
	public function __construct() {
		$this->quackers = array();
	}
	
	/**
	 * 添加到数组中
	 *
	 * @param Quackable $quacker
	 */
	public function add(Quackable $quacker) {
		array_push($this->quackers, $quacker);
	}
	
	/**
	 * @see Quackable::quack()
	 * 原书中这里是用迭代器实现, 这里的代码更加类似于递归
	 */
	public function quack() {
		foreach ($this->quackers as $key => $value) {
			//var_dump($value);
			$value->quack();
			//echo "<br /><hr /><br />";
		}
	} /* END func quack */
} /* END class Flock */

?>